//
//  WYMainViewController.m
//  微博oc
//
//  Created by 王玉东 on 16/4/7.
//  Copyright © 2016年 wyd. All rights reserved.
//

#import "WYMainViewController.h"
#import "WYDiscoverViewController.h"
#import "WYHomeViewController.h"
#import "WYMessageViewController.h"
#import "WYProfileViewController.h"
#import  "WYTabBar.h"

@interface WYMainViewController ()

@end

@implementation WYMainViewController

+(void)initialize{

    UITabBarItem *item = [UITabBarItem appearance];
    
    [item setTitleTextAttributes:@{
                                  NSForegroundColorAttributeName:[UIColor orangeColor]
                                  
                                  } forState:UIControlStateSelected];
    
   


}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    
    [self loadController];
    
    [self setValue:[[WYTabBar alloc]init] forKey:@"tabBar"];
}

#pragma mark - 加载主控制器上的分控制器
-(void)loadController{
    
    
    [self loadTabbar:[[WYHomeViewController alloc]init] and:@"主页" and:@"tabbar_home"];
    
    [self loadTabbar:[[WYMessageViewController alloc] init ] and:@"信息" and:@"tabbar_message_center"];
    
    [self loadTabbar:[[WYDiscoverViewController alloc] init] and:@"发现" and:@"tabbar_discover"];
    
    [self loadTabbar:[[WYProfileViewController alloc] init] and:@"我" and:@"tabbar_profile"];

}




-(void)loadTabbar:(UIViewController *) vc and:(NSString *)title and:(NSString *) image{

    vc.tabBarItem.image = [UIImage imageNamed:image];
    
    NSString *str = [NSString stringWithFormat:@"%@_selected",image];
    
    //设置image的属性imageWithRenderingMode---->总是显示
    [vc.tabBarItem setSelectedImage:[[UIImage imageNamed:str] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ]];

    vc.title = title;
    
    UINavigationController  *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    
    [self addChildViewController:nav];
    

}






@end
